
package com.craterhill.java.ems.web;

import java.security.Principal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.craterhill.java.ems.common.beans.Staff;
import com.craterhill.java.ems.service.SchoolService;
import com.craterhill.java.ems.service.StaffService;
import com.craterhill.java.ems.web.authenticator.CHTCAuthenticatorToken;

@Controller
public class HomeController {

	private final StaffService staffService;
	private final SchoolService schoolService;

	@Autowired
	public HomeController(final StaffService staffService, final SchoolService schoolService) {
		this.staffService = staffService;
		this.schoolService = schoolService;
	}

	@RequestMapping("/home.ems")
	public String staffHome(final Principal principal) {
		CHTCAuthenticatorToken authenticatorToken = (CHTCAuthenticatorToken) principal;
		Staff staff = authenticatorToken.getLoggedStaff();
		int schoolId = staff.getSchoolViewingId();
		
		schoolService.getSchool(schoolId);
		
		return "home";
	}
}
